package com.un.web.topic.controller;

import cn.hutool.db.Page;
import com.github.pagehelper.PageInfo;
import com.un.core.common.R;
import com.un.web.topic.domian.entity.TopicType;
import com.un.web.topic.service.TopicTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author xingjian
 * @Date 2023-01-31
 **/
@RestController
@RequestMapping("/topic_type")
public class TopicTypeController {

    @Autowired
    private TopicTypeService topicTypeService;


    @GetMapping("selectOne")
    public R selectOne(Integer id) {
        return R.success(topicTypeService.getById(id));
    }

    @GetMapping("listPage")
    public R getAll(Page page){
        PageInfo<TopicType> list = topicTypeService.selectAllByPage(page);
        return R.success(list);
    }
    @GetMapping("list")
    public R getAll( ){
        List<TopicType> list = topicTypeService.list();
        return R.success(list);
    }

    @PostMapping("add")
    public R insertType(@RequestBody TopicType topicType){
        topicTypeService.saveOrUpdate(topicType);
        return R.success();
    }
    @DeleteMapping("delete/{id}")
    public R deleteTopicType(@PathVariable Integer id){
        topicTypeService.removeById(id);
        return R.success();
    }

}
